package xyz.fivefaith.tool.mybatis.injector.method;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;

import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

import xyz.fivefaith.tool.mybatis.injector.AbstractFaithMethod;

/**
 * 根据 whereEntity 条件，更新记录(但是不包含逻辑删除)根据 whereEntity 条件，更新记录(但是不包含逻辑删除)
 *
 * @author zhaoanchi
 * @version 1.0
 * @since 2023-09-18 16:02
 */
public class AlwaysSelectBatchIds extends AbstractFaithMethod {

    /**
     * @param name 方法名
     * @since 3.5.0
     */
    public AlwaysSelectBatchIds(String name) {
        super(name);
    }

    public AlwaysSelectBatchIds() {
        super("alwaysSelectBatchIds");
    }

    @Override
    public MappedStatement injectMappedStatement(
            Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        SqlMethod sqlMethod = SqlMethod.SELECT_BATCH_BY_IDS;
        SqlSource sqlSource =
                languageDriver.createSqlSource(
                        configuration,
                        String.format(
                                sqlMethod.getSql(),
                                sqlSelectColumns(tableInfo, false),
                                tableInfo.getTableName(),
                                tableInfo.getKeyColumn(),
                                SqlScriptUtils.convertForeach("#{item}", COLL, null, "item", COMMA),
                                ""),
                        Object.class);
        return addSelectMappedStatementForTable(mapperClass, methodName, sqlSource, tableInfo);
    }
}
